package com.example.datn.adapter;

import java.util.ArrayList;

import com.example.datn.R;
import com.example.datn.objects.AlbumObject;

import android.app.Activity;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class AlbumItemAdapter extends ArrayAdapter<AlbumObject> {

	Activity context = null;
	ArrayList<AlbumObject> myArray = null;
	int layoutId;
	ImageView albumImage;

	public AlbumItemAdapter(Activity _context, int _resource,
			ArrayList<AlbumObject> _objects) {
		super(_context, _resource, _objects);

		this.context = _context;
		this.layoutId = _resource;
		this.myArray = _objects;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = context.getLayoutInflater();
		convertView = inflater.inflate(layoutId, null);

		albumImage = (ImageView) convertView
				.findViewById(R.id.img_listAlbum_imageAlbum);
		TextView albumName = (TextView) convertView
				.findViewById(R.id.tv_listAlbum_albumName);

		AlbumObject album = myArray.get(position);

		Bitmap bitmap = album.getBitmapImage();
		if (bitmap != null)
			albumImage.setImageBitmap(bitmap);
		else
			albumImage.setImageDrawable(albumImage.getContext().getResources()
					.getDrawable(R.drawable.ic_launcher));

		albumName.setText(album.albumName);

		return convertView;
	}

}
